﻿using System.Collections;
using System.Collections.Generic;
using AutoMapper;
using Enferno.Public.Web.Mappers.Resolvers;
using Enferno.Public.Web.Models;
using Enferno.Public.Web.ViewModels;
using Enferno.StormApiClient.Products;

namespace Enferno.Public.Web.Mappers.ProductProfiles
{
    public class ProductModelToProductViewModelProfile : ProductBaseModelToProductBaseViewModelProfile<
        ProductBaseModel<VariantModel, ProductManufacturerModel, ProductListModel, ProductItemModel, FilterModel, ProductFileModel, PriceModel, OnHandStatusModel, ParametricModel, ParametricValueModel>,
        VariantModel,
        ProductManufacturerModel,
        ProductListModel,
        ProductItemModel,
        FilterModel,
        ProductFileModel,
        PriceModel,
        OnHandStatusModel,
        ParametricModel,
        ParametricValueModel,
        ProductViewModel,
        VariantViewModel,
        FileViewModel,
        ParametricViewModel,
        ParametricValueViewModel>
    {
        
    }

    public class CustomerProductModelToCustomProductViewModelProfile<TProductModel, TProductViewModel> :
        ProductBaseModelToProductBaseViewModelProfile
            <TProductModel, VariantModel, ProductManufacturerModel, ProductListModel, ProductItemModel, FilterModel,
                ProductFileModel, PriceModel, OnHandStatusModel, ParametricModel, ParametricValueModel,
                TProductViewModel, VariantViewModel, FileViewModel, ParametricViewModel, ParametricValueViewModel>
        where TProductModel :
            ProductBaseModel
                <VariantModel, ProductManufacturerModel, ProductListModel, ProductItemModel, FilterModel,
                    ProductFileModel, PriceModel, OnHandStatusModel, ParametricModel, ParametricValueModel>
        where TProductViewModel :
            ProductBaseViewModel<VariantViewModel, FileViewModel, ParametricViewModel, ParametricValueViewModel>
    {
        
    } 

    public class ProductBaseModelToProductBaseViewModelProfile<
        TProductModel, 
        TVariantModel,
        TProductManufacturerModel,
        TProductListModel,
        TProductItemModel,
        TFilterModel,
        TProductFileModel,
        TPriceModel,
        TOnHandStatusModel,
        TParametricModel,
        TParametricValueModel,
        TProductViewModel,
        TVariantViewModel,
        TFileViewModel,
        TParametricViewModel,
        TParametricValueViewModel> : Profile
        where TProductModel: ProductBaseModel<TVariantModel, TProductManufacturerModel, TProductListModel, TProductItemModel, TFilterModel, TProductFileModel, TPriceModel, TOnHandStatusModel, TParametricModel, TParametricValueModel>
        where TVariantModel: VariantBaseModel<TOnHandStatusModel, TPriceModel, TProductFileModel, TParametricModel, TParametricValueModel>
        where TProductManufacturerModel: ProductManufacturerModel
        where TProductListModel: ProductListBaseModel<TProductItemModel, TFilterModel, TVariantModel, TProductFileModel, TProductManufacturerModel, TPriceModel, TOnHandStatusModel, TParametricModel, TParametricValueModel>
        where TProductItemModel: ProductItemBaseModel<TVariantModel, TProductFileModel, TProductManufacturerModel, TPriceModel, TOnHandStatusModel, TParametricModel, TParametricValueModel>
        where TFilterModel: FilterModel
        where TProductFileModel: ProductFileModel
        where TPriceModel: PriceModel
        where TOnHandStatusModel: OnHandStatusModel
        where TParametricModel: ParametricBaseModel<TParametricValueModel>
        where TParametricValueModel: ParametricValueModel
        where TProductViewModel: ProductBaseViewModel<TVariantViewModel, TFileViewModel, TParametricViewModel, TParametricValueViewModel>
        where TVariantViewModel: VariantBaseViewModel<TFileViewModel, TParametricViewModel, TParametricValueViewModel>
        where TFileViewModel: FileViewModel
        where TParametricViewModel: ParametricBaseViewModel<TParametricValueViewModel>, new()
        where TParametricValueViewModel: ParametricValueViewModel, new()

    {
        protected override void Configure()
        {
            Mapper.CreateMap<TProductModel, TProductViewModel>()
                .ForMember(to=> to.OnHandStatusText1, opts=> opts.MapFrom(from=> from.OnHandStatus.Text1))
                .ForMember(to => to.OnHandStatusText2, opts => opts.MapFrom(from => from.OnHandStatus.Text2))
                .ForMember(to => to.OnHandStatus, opts => opts.MapFrom(from => from.OnHandStatus.Status))
                .ForMember(to => to.OnHandStatusCount, opts => opts.MapFrom(from => from.OnHandStatus.Count))
                .ForMember(to => to.DisplayPrice, opts => opts.MapFrom(from => from.Price.Display))
                .ForMember(to => to.CatalogPrice, opts => opts.MapFrom(from => from.Price.Catalog))
                .ForMember(to => to.VatRate, opts => opts.MapFrom(from => from.Price.VatRate))
                .ForMember(to => to.PriceListId, opts => opts.MapFrom(from => from.Price.PricelistId))
                .ForMember(to => to.Files,
                    opts =>
                        opts.ResolveUsing(from => Mapper.Map<IList<TProductFileModel>, IList<TFileViewModel>>(from.Files)))
                .ForMember(to => to.VariantParametrics,
                    opts =>
                        opts.ResolveUsing(
                            from =>
                                Mapper.Map<IList<TParametricModel>, IList<TParametricViewModel>>(from.VariantParametrics)))
                .ForMember(to => to.Variants,
                    opts =>
                        opts.ResolveUsing(
                            from =>
                                Mapper.Map<IList<TVariantModel>, IList<TVariantViewModel>>(from.Variants)));

        }

        public override string ProfileName
        {
            get { return GetType().Name; }
        }
    }
}
